<%@ page contentType="text/xml;charset=utf-8"
	import="java.sql.Connection, java.sql.PreparedStatement, java.sql.ResultSet
	, git.bankview.sl.db.DBConnectionFactory
	, git.bankview.wl.auth.userGroups.TransCheck"
%><%@ include file="/jsp/inc/pageUtils.jsp"
%><% response.addHeader("Cache-Control", "no-cache"); %>
<jsp:useBean id="oLogon" class="git.bankview.wl.bean.LogonBean" scope="session" />
<tasks>
<%
	//TransCheck.check(oLogon.getUsername(), "90060", 1);
	int taskid = Integer.parseInt(request.getParameter("taskid"));
	java.sql.Date datekey = sqlDate(request.getParameter("datekey"));
	Connection conn = DBConnectionFactory.getCoreConnection();
	try
	{
		PreparedStatement psDep = conn.prepareStatement("select d.deptaskid, t.taskdesc from taskdependence d, taskschedule t where d.taskid=? and d.datekey=? and d.deptaskid = t.taskid and d.datekey = t.datekey");
		try
		{
			PreparedStatement psSub = conn.prepareStatement("select d.taskid, t.taskdesc from taskdependence d, taskschedule t where d.deptaskid=? and d.datekey=? and d.taskid = t.taskid and d.datekey = t.datekey");
			try
			{
				PreparedStatement ps = conn.prepareStatement("select * from taskschedule where taskid=? and datekey=?");
				try
				{
					ps.setInt(1, taskid);
					ps.setDate(2, datekey);
					ResultSet rs = ps.executeQuery();
					try
					{
						while (rs.next())
						{
							String execurl = rs.getString("execurl").trim();
							int p = execurl.indexOf("://");
							String oProtocol = execurl.substring(0, p);
							String oTaskStr = execurl.substring(p + 3);
							String requestUri = oTaskStr;
							p = oTaskStr.indexOf('?');
							String[] vParam = null;
							if (0 < p)
							{
								requestUri = requestUri.substring(0, p);
								oTaskStr = oTaskStr.substring(p + 1);
								vParam = oTaskStr.split("&");
							}
							else
							{
								oTaskStr = null;
							}
							
							String errmsg = rs.getString("errmsg");
							String taskdesc = rs.getString("taskdesc");
							java.sql.Timestamp exectime = rs.getTimestamp("exectime");
							java.sql.Timestamp termtime = rs.getTimestamp("termtime");
	%>
		<task>
			<datekey><%=cstr(rs.getDate("datekey"))%></datekey>
			<taskid><%=rs.getString("taskid")%></taskid>
			<execurl><![CDATA[<%=execurl%>]]></execurl>
			<retrymax><%=rs.getString("retrymax")%></retrymax>
			<statuscode><%=rs.getString("statuscode")%></statuscode>
			<exectime><%=null == exectime ? "" : cstr(rs.getTimestamp("exectime"))%></exectime>
			<termtime><%=null == termtime ? "" : cstr(rs.getTimestamp("termtime"))%></termtime>
			<retrytimes><%=rs.getString("retrytimes")%></retrytimes>
			<errmsg><![CDATA[<%= (null != errmsg) ? errmsg.trim() : ""%>]]></errmsg>
			<taskdesc><![CDATA[<%= (null != taskdesc) ? taskdesc.trim() : ""%>]]></taskdesc>
			<isignored><%=rs.getString("isignored")%></isignored>
			<protocol><%=oProtocol%></protocol>
			<requestURI><![CDATA[<%=requestUri%>]]></requestURI>
			<requestParameters>
<%
							for (int i = 0; null != vParam && i < vParam.length; ++i)
							{
								int ep = vParam[i].indexOf("=");
								if (ep <= 0)
									throw new IllegalArgumentException("参数'" + vParam[i] + "'没有值");
		
								String pName = vParam[i].substring(0, ep);
								String pVal = vParam[i].substring(ep + 1);
%>				<requestParameter name="<%=pName%>"><![CDATA[<%=pVal%>]]></requestParameter>
<%
							}
%>			</requestParameters>
<%
							psDep.setInt(1, taskid);
							psDep.setDate(2, datekey);
							ResultSet rsCorr = psDep.executeQuery();
							try
							{
%>			<depTaskList>
<%
								while(rsCorr.next())
								{
%>				<depTask id="<%=rsCorr.getInt(1)%>"><%=rsCorr.getString(2).trim()%></depTask>
<%
								}
%>			</depTaskList>
<%
							}
							finally
							{
								rsCorr.close();
							}

							psSub.setInt(1, taskid);
							psSub.setDate(2, datekey);
							rsCorr = psSub.executeQuery();
							try
							{
%>			<subTaskList>
<%
								while(rsCorr.next())
								{
%>				<subTask id="<%=rsCorr.getInt(1)%>"><%=rsCorr.getString(2).trim()%></subTask>
<%
								}
%>			</subTaskList>
<%
							}
							finally
							{
								rsCorr.close();
							}
%>		</task>
	<%
						}
					}
					finally
					{
						rs.close();
					}
				}
				finally
				{
					ps.close();
				}
			}
			finally
			{
				psSub.close();
			}
		}
		finally
		{
			psDep.close();
		}
	}
	finally
	{
		conn.close();
	}
	%>
</tasks>
